package com.yanqu.road.entity.player;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 玩家维度活动相关数据
 */
@FieldTypeAnnotation(tableName = "t_u_user_act_data")
public class UserActData extends DataObject {

    @FieldTypeAnnotation(desc = "玩家ID", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "完成过引导的活动类型")
    private Set<String> comGuideActTypes = new HashSet<>();

    @FieldTypeAnnotation(desc = "2选1事件正确选项,k：大活动类型_小类型,k：正确选项ID,v:正确选项")
    private Map<String, Map<String, String>> chooseTrueIndexMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "更新时间)")
    private long updateTime;

    @FieldTypeAnnotation(desc = "创建时间)")
    private long createTime;

    public UserActData() {}

    public UserActData(long userId) {
        this.userId = userId;
        this.comGuideActTypes = new HashSet<>();
        this.createTime = System.currentTimeMillis();
        setInsertOption();
    }

    public long getUserId() {
        return userId;
    }
    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }
    }

    public Set<String> getComGuideActTypes() {
        return comGuideActTypes;
    }

    public void setComGuideActTypes(Set<String> comGuideActTypes) {
        this.comGuideActTypes = comGuideActTypes;
    }

    public void addComGuideActType(String actType) {
        comGuideActTypes.add(actType);
        setOp(DataStatus.Update);
    }

    public long getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(long updateTime) {
        if (this.updateTime != updateTime) {
            this.updateTime = updateTime;
            setOp(DataStatus.Update);
        }
    }

    public long getCreateTime() {
        return createTime;
    }
    public void setCreateTime(long createTime) {
        if (this.createTime != createTime) {
            this.createTime = createTime;
            setOp(DataStatus.Update);
        }
    }

    public Map<String, Map<String, String>> getChooseTrueIndexMap() {
        return chooseTrueIndexMap;
    }

    public String getChooseTrueIndex(String actType, String chooseId) {
        Map<String, String> map = chooseTrueIndexMap.get(actType);
        if (map == null) {
            return null;
        }
        return map.get(chooseId);
    }

    public void setChooseTrueIndexMap(Map<String, Map<String, String>> chooseTrueIndexMap) {
        this.chooseTrueIndexMap = chooseTrueIndexMap;
    }

    public void addChooseTrueIndex(String actType, String chooseId, String chooseTrueIndex) {
        Map<String, String> map = chooseTrueIndexMap.computeIfAbsent(actType, k -> new ConcurrentHashMap<>());
        map.put(chooseId, chooseTrueIndex);
        setOp(DataStatus.Update);
    }
}
